package com.example.demo.util;

import org.apache.commons.codec.binary.Base64;


public class BASE64 {
	/**
	 * BASE64解密
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	public static String decrypt(String key) {
		if (null != key) {
			return new String(Base64.decodeBase64(key.getBytes()));
		}
		return null;

	}

	/**
	 * BASE64加密
	 * 
	 * @param key
	 * @return
	 * @throws Exception
	 */
	public static String encrypt(String key) {

		if (null != key) {
			return new String(Base64.encodeBase64(key.getBytes()));
		}
		return key;

	}

	public static void main(String[] args) throws Exception {

		String data = BASE64.encrypt("978880162@qq.com:1q2w3e4r");
		System.out.println(data);
		System.out.println("解密后：" + BASE64.decrypt("c21vaGFtZWRub2hAbGVub3ZvLmNvbTpTdXJAaXlhMjM="));
	}

}
